import plotly.graph_objs as go
from plotly.offline import plot
from database import get_all_events


def create_timeline():
    events = get_all_events()
    years = [event[0] for event in events]
    descriptions = [event[1] for event in events]

    # 创建时间轴图表
    fig = go.Figure()
    fig.add_trace(go.Scatter(
        x=years,
        y=[1] * len(years),
        mode='markers+text',
        text=descriptions,
        textposition='top center'
    ))

    fig.update_layout(
        title="中华人民共和国重大历史事件时间轴",
        xaxis_title="年份",
        yaxis=dict(visible=False)
    )

    # 保存为 HTML 文件
    plot(fig, filename='./templates/timeline.html', auto_open=False)
